package com.leaderhr.fishshop.service.product;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.inject.Inject;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.leaderhr.fishshop.dao.product.IProductBrandDao;
import com.leaderhr.fishshop.dao.product.IProductTypeDao;
import com.leaderhr.fishshop.form.AdminPager;
import com.leaderhr.fishshop.form.DataGrid;
import com.leaderhr.fishshop.form.Pager;
import com.leaderhr.fishshop.form.ProductTypeForm;
import com.leaderhr.fishshop.form.Tree;
import com.leaderhr.fishshop.model.product.ProductBrand;
import com.leaderhr.fishshop.model.product.ProductType;
@Service("ProductBrandService")
public class ProductBrandServiceImpl implements IProductBrandService {
	
	private IProductBrandDao productBrandDao;

	
	public IProductBrandDao getProductBrandDao() {
		return productBrandDao;
	}
	@Inject
	public void setProductBrandDao(IProductBrandDao productBrandDao) {
		this.productBrandDao = productBrandDao;
	}

	@Override
	public ProductBrand add(ProductBrand productBrand) {
		productBrand.setCode(UUID.randomUUID().toString());
		return this.productBrandDao.addProductBrand(productBrand);
		
	}
	@Override
	public DataGrid<ProductBrand> dataGrid(ProductBrand productBrand,
			AdminPager ap) {
		DataGrid<ProductBrand>  dg= new DataGrid<ProductBrand>();
		String hql = "from ProductBrand pb";
		String totalHql = "select count(*)" + hql;
		List<ProductBrand> l  = productBrandDao.find(hql, ap.getPage(), ap.getRows());
		dg.setTotal(productBrandDao.count(totalHql));
		dg.setRows(l);
		return dg;
		//return productBrandDao.find("from ProductBrand pb", ap.getPage(), ap.getRows());
	}
	
	

	
	

	
}
